// 获取今日详细时间
export function getTearMonthDat () {
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分  
    return {
        year,
        month,
        day,
        hh,
        mm
    }; 
}

/**
 *  
 *  验证函数
 */
export const verifys = {
    // 手机验证
    isPoneAvailable: (str) => {
        console.log(str);
        var myreg=/^1[3-578]\d{9}$/;
        if (!myreg.test(str)) {
            return false;
        } else {
            return true;
        }
    },
    // 空字符验证
    checkStrIsNull: (str) => {
        if ( !str || str === 'null' || str === 'undefined' ) {
            return true;
        }
        let newStr = trim(str);
        if (newStr === '' ) {
            return true;
        }
        return false;
    }
}

/**
 *  将毫秒书转换为 xx小时xx分钟xx秒
 * @param { String } msd 毫秒数
 * @returns { Object }  时间对象包括 时分秒
 */
export function milliSecondToDate (msd) {
    var time = parseFloat(msd) / 1000;
    let timeObj = {
        hour: '',
        minute: '',
        second: ''
    }
    if (null != time && "" != time) {
        if (time > 0 && time < 60 * 60) {
            timeObj.hour =  0,
            timeObj.minute =  parseInt(time / 60.0);
            timeObj.second =  parseInt(time -  timeObj.minute  * 60);
        }
        // && time < 60 * 60 * 24 天数
        else if (time >= 60 * 60 ) {
            timeObj.hour   = parseInt(time / 3600);
            timeObj.minute = parseInt(time/60 - timeObj.hour * 60);
            timeObj.second = parseInt(time - timeObj.minute * 60 - timeObj.hour*3600 ); 
        }
        else {
            timeObj.hour = 0;
            timeObj.minute = 0;
            timeObj.second = 0
        }
    }
    return timeObj;
}
/**
 *  将毫秒转换为 时间对象
 * @param { String } msd 毫秒数
 * @returns { Object }  时间对象包括 天时分秒
 */
export const transformDate = (msd) => {
    var time = parseFloat(msd) / 1000;
    let timeObj = {
        day: 0,
        hour: 0,
        minute: 0,
        second: 0
    };
    if (time <=0 ) {
        return timeObj;
    }
    const checkDateSpec = () => {
        timeObj.day = timeObj.day > 9 ? timeObj.day + '': '0' + timeObj.day;
        timeObj.hour = timeObj.hour > 9 ? timeObj.hour + '': '0' + timeObj.hour;
        timeObj.minute = timeObj.minute > 9 ? timeObj.minute + '': '0' + timeObj.minute;
        timeObj.second = timeObj.second > 9 ? timeObj.second + '': '0' + timeObj.second;
    }
    if (time > 0 && time < 60 * 60) {
        timeObj.minute =  parseInt(time / 60.0);
        timeObj.second =  parseInt(time -  timeObj.minute  * 60);
        checkDateSpec();
        return timeObj;
    }
    if (time >= 60 * 60 && time < 60 * 60 *24 ) {
        timeObj.hour   = parseInt(time / 3600);
        timeObj.minute = parseInt(time/60 - timeObj.hour * 60);
        timeObj.second = parseInt(time - timeObj.minute * 60 - timeObj.hour*3600 );
        checkDateSpec(); 
        return timeObj;
    }
    if (time >= 60 * 60 *24 ) {
        let dayMis = 60 * 60 *24;
        timeObj.day   = parseInt(time / dayMis);
        timeObj.hour   = parseInt(time / 3600) - timeObj.day * 24;
        timeObj.minute = parseInt(time/60 - timeObj.day * 24*60 - timeObj.hour * 60);
        timeObj.second = parseInt(time - timeObj.minute * 60 - timeObj.hour*3600 - timeObj.day * dayMis  ); 
        checkDateSpec();
        return timeObj;
    }
}
function trim(str){ //删除左右两端的空格
　　  return str.replace(/(^\s*)|(\s*$)/g, "");
}